<template>
  <CompOperate v-if="getReportStepInfo" :field="field" :designer="designer" :design-state="designState"
               :parent-list="parentList" :parent-widget="parentWidget" :sub-form-row-id="subFormRowId"
               :sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex"
               :index-of-parent-list="indexOfParentList" :display-style="field.options.displayStyle">
    <div class="scene-tips-widget" :style="getStyle('wrap')">
      <template v-if="true">
        <div class="right" :key="uuid">
          <NoticeBarInfo :options='getScrollOptions' ref="noticeBarInfo"/>
        </div>
      </template>
    </div>
  </CompOperate>
</template>

<script>
import {Icon, NoticeBar} from 'vant';
import {pxToVw, remToPx} from '@/utils/common'
import emitter from "@/utils/designer/emitter";
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {getReportStepInfo} from "@/store/modules/getters";
import {v4 as uuid} from "uuid";
import NoticeBarInfo from "@c/public/noticeBar/index.vue";

export default {
  name: "scene-tips-center-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  props: {
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    selectedWidget: Object,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    noticeContent: {
      type: String,
      default: '',
    },
    enableScroll: {
      type: Boolean,
      default: false,
    },
  },

  components: {
    NoticeBarInfo,
    Icon,
    NoticeBar,
    CompOperate,
  },

  data() {
    return {
      uuid: uuid(),
      list: [],
      optionsInfo: Object(),
    }
  },

  computed: {
    // 获取报到机的步距
    getReportStepInfo() {
      let info = this.$store.getters['getReportStepInfo'];
      return info !== 1
    },

    // 滚动的设置项目
    getScrollOptions() {
      const self = this;
      let info = (self.optionsInfo) || Object();
      let barInfo = (this.$refs.noticeBarInfo);
      let speedInfo = (info.speed) > 10 ? 10 : (info.speed)
      let speedRem = (parseInt(remToPx(speedInfo)))
      // if(barInfo){
      return {
        text: `${info.contentInfo}`,               // 通知内容
        fontSize: (info.listFontSize),             // 通知内容文字大小（默认16px）
        fontWeight: (info.listFontWeight),
        color: (info.listFontColor),               // 通知内容文字颜色(默认#f60)
        delay: '1000',                             // 动画延迟时间(默认一秒后开始滚动，单位毫秒)
        speed: speedRem,                         // 滚动速率默认50 (px/s)
        scrollable: (info.scrollable),
        position: 'center'
      }
      // }
    },

    // 获取设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Object();
        let Obj = Object();
        switch (val) {
          case 'wrap':
            if (!!info.backgroundColor) {
              Reflect.set(Obj, 'backgroundColor', `${(info.backgroundColor)}`);
            } else {
              Reflect.deleteProperty(Obj, 'backgroundColor');
            }
            Reflect.set(Obj, 'height', pxToVw(info.contentHeight));
            return Obj;
          case 'head':
            Reflect.set(Obj, 'fontSize', pxToVw(info.headerFontSize));
            Reflect.set(Obj, 'color', `${(info.headerColor)}`);
            return Obj;
          case 'list':
            Reflect.set(Obj, 'color', `${(info.listFontColor)}`);
            Reflect.set(Obj, 'fontSize', pxToVw(info.listFontSize));
            Reflect.set(Obj, 'fontWeight', info.listFontWeight);
            return Obj;
        }
      }
    },


  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "TipsInfo":
          console.log(`温馨提示-数据处理逻辑-${data}`)
          break
      }
    }
  },

  watch: {
    // 获取配置项
    field: {
      handler: function (val) {
        this.uuid = uuid();
        this.optionsInfo = (val.options.tipsConfig);
      },
      deep: true,
      immediate: true
    },
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-tips-widget {
  background-color: #fff;
  display: flex;
  color: #333;
  height: 100px;
  overflow: hidden;
  font-size: 28px;
  padding: 0 28px;
  box-sizing: border-box;
  @include background('design/tips-bg×2');
  backdrop-filter: blur(8px);

  .right {
    display: flex;
    flex-direction: row;
    overflow: hidden;
    cursor: pointer;
    width: calc(100%);

    .van-notice-bar {
      background: transparent;
      color: black;
      height: 100%;
      width: 100%;
      font-size: 38px;

      :deep(.van-notice-bar__wrap) {
        height: 100%;
        width: 100%;
        margin-top: 20px;
        align-self: center;
        justify-content: center;
      }

      :deep(.van-notice-bar__content) {
        display: flex;
        align-items: center;
        align-self: center;
        line-height: 58px;
        height: 100% !important;
      }
    }
  }
}
</style>
